# type:ignore
import traceback
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *
from moudles.Common.common import *


class DisplayColorCheckReport(object):
    """
    展示实验报告单的UI界面
    """

    def __init__(self, mainUI) -> None:
        self.mainUI = mainUI

    def displayColorCheckReport(self, img_path, all_image_formData_dict):
        # 获取当前点击的图片路径对应的数据
        image_data = all_image_formData_dict.get(img_path, '')
        if image_data:
            self.mainUI.pushButton_6.setStyleSheet("color: black;")
            self.mainUI.pushButton_6.setText('识别结果')

            try:
                # 填写识别结果标题
                if image_data[0]:
                    header_title = image_data[0]
                    hospital_name = header_title.get('检测医院名称', '')
                    self.mainUI.pushButton_6.setText(f'识别结果-{hospital_name}')

                # 填写识别结果基本信息
                if image_data[1]:
                    self.formBaseInfo(image_data[1])

                # 填写描述
                if image_data[2]:
                    self.formDescInfo(image_data[2])

                # 填写提示信息
                if image_data[3]:
                    self.formTipInfo(image_data[3])

                # 填写识别结果其他信息
                if image_data[4]:
                    self.formOtherInfo(image_data[4])
            except:
                print(traceback.print_exc())
        else:
            self.mainUI.pushButton_6.setStyleSheet("color: red;")
            self.mainUI.pushButton_6.setText(f'识别结果-未找到数据，请稍后再试试！')

    def formBaseInfo(self, header_data):
        name = header_data.get('姓名', '')
        self.mainUI.nameEdit_2.setText(name)
        sex = header_data.get('性别', '')
        self.mainUI.sexEdit_2.setText(sex)
        age = header_data.get('年龄', '')
        self.mainUI.ageEdit_2.setText(age)
        medicalRecordNumber = header_data.get('病历号', '')
        self.mainUI.numberEdit_2.setText(medicalRecordNumber)
        department = header_data.get('科室', '')
        self.mainUI.departmentEdit_2.setText(department)
        specimenCondition = header_data.get('标本情况', '')
        self.mainUI.situationEdit_2.setText(specimenCondition)
        checkpoint = header_data.get('检查部位', '')
        self.mainUI.plainTextEdit.setPlainText(checkpoint)
        clinicalHistory = header_data.get('临床病史', '')
        self.mainUI.plainTextEdit_2.setPlainText(clinicalHistory)

    def formDescInfo(self, desc_data):
        descript = desc_data.get('描述', '')
        self.mainUI.plainTextEdit_4.setPlainText(descript)

    def formTipInfo(self, tip_data):
        tips = tip_data.get('提示', '')
        self.mainUI.plainTextEdit_3.setPlainText(tips)

    def formOtherInfo(self, footer_data):
        inspector = footer_data.get('检查医师', '')
        self.mainUI.inspectorEdit_2.setText(inspector)
        reviewer = footer_data.get('审核医师', '')
        self.mainUI.reviewerEdit_2.setText(reviewer)
        hospitalPphoneNumber = footer_data.get('医院电话', '')
        self.mainUI.hospitalTelEdit_2.setText(hospitalPphoneNumber)
        reportDate = footer_data.get('报告日期', '')
        self.mainUI.reportDataEdit_2.setText(reportDate)
        hospitalAddress = footer_data.get('医院地址', '')
        self.mainUI.hospitalAddrEdit_2.setText(hospitalAddress)
